#include "mine_main.h"
#include "mine_usart1.h"
#include "mine_usart2.h"
#include "FreeRTOS.h"
#include "task.h"
#include "stdlib.h"
#include "stdio.h"
#include "nvic.h"
#include "delay.h"
#include "mine_fly_control.h"
#include "mine_remoter_ctrl.h"
#include "mine_monitor_stack_info.h"

TaskHandle_t mine_startTaskHandle;

TaskHandle_t hello_task_handler;

void  hello(void *pvParameters){
	while(1){
		printf("hello\n");
		vTaskDelay(2000);
	}
	
}

void mine_startTask(void *pvParameters)
{
    // 串口
    mine_usart1_init(); // printf
    mine_usart2_init(); // 接收nrf51822无线芯片的消息
    mine_fly_control_init();
		
    //
    // print_version();
    //
    taskENTER_CRITICAL();

    //
    /* 创建此任务 */
		xTaskCreate(hello, "hello", 128, NULL, 2, &hello_task_handler);
    // BaseType_t xReturn = xTaskCreate(stack_heap_analysis_task, "stack_heap_analysis_task", 256, NULL, 2, &stackHeapAnalysisTaskHandler);
    xTaskCreate(mine_fly_control_task, "mine_fly_control_task", 512, NULL, 5, &mine_fly_control_task_handler);
    //xTaskCreate(mine_remoter_ctrl_task, "mine_remoter_ctrl_task", 512, NULL, 4, &mine_remoter_ctrl_task_handler);

    //
    vTaskDelete(NULL);

    taskEXIT_CRITICAL();
}

void mine_main()
{

    nvicInit(); /*中断配置初始化*/

    delay_init(96); /*delay初始化*/

    xTaskCreate(mine_startTask, "START_TASK", 300, NULL, 4, &mine_startTaskHandle); /*创建起始任务*/

    vTaskStartScheduler(); /*开启任务调度*/

    while (1)
    {
    };
}
